using System.Threading;
using Legend.Threading;
using NUnit.Framework;

namespace Legend.Core.Tests.Threading.ThreadingExtensionsTests
{
    [TestFixture]
    public class ReaderWriterLockSlimFactoryTests
        : ISynchronizationManagerFactoryContractTests
    {
        private ReaderWriterLockSlimFactory factory;

        [SetUp]
        public void SetUp()
        {
            this.OnSetUp();
        }

        protected virtual void OnSetUp()
        {
            this.factory = new ReaderWriterLockSlimFactory();
        }

        protected override ISynchronizationManagerFactory CreateFactory()
        {
            return new ReaderWriterLockSlimFactory();
        }

        [Test]
        public void CreateSynchronizationManager_should_return_adapter_of_correct_Type()
        {
            // Arrange

            // Act
            var result = this.factory.CreateSynchronizationManager(LockRecursionPolicy.SupportsRecursion);

            // Assert
            Assert.That(result, Is.InstanceOf<ReaderWriterLockSlimAdapter>());
        }

        [Test]
        public void CreateSynchronizationManager_should_return_manager_that_does_not_support_recursion_when_NoRecursion_is_specified()
        {
            // Arrange

            // Act
            var result = this.factory.CreateSynchronizationManager(LockRecursionPolicy.NoRecursion);

            // Assert
            Assert.That(result.RecursionPolicy, Is.EqualTo(LockRecursionPolicy.NoRecursion));
        }
    }
}
